package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CustomerInfoApiService;
import com.yixun.qfbao.apidto.AddOrEditCustomerInfoReqDto;
import com.yixun.qfbao.apidto.AddOrEditCustomerInfoResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.dto.CustomerInfoDto;
import com.yixun.qfbao.vo.AddOrEditCustomerInfoReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 编辑客户信息
 * 
 * @author jhsong
 *		
 */
@Service("addOrEditCustomerInfoHander")
public class AddOrEditCustomerInfoHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(AddOrEditCustomerInfoHander.class);
	
	@Autowired
	private CustomerInfoApiService customerInfoApiService;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		AddOrEditCustomerInfoReqVo req = (AddOrEditCustomerInfoReqVo)reqDto;
		AddOrEditCustomerInfoReqDto reqDto1 = req.getParams();
		BaseResponseDTO<AddOrEditCustomerInfoResDto> res = new BaseResponseDTO<>();
		AddOrEditCustomerInfoResDto resDto = new AddOrEditCustomerInfoResDto();
		try {
	 		CustomerInfoDto customerInfoDto = customerInfoApiService.addOrEditCustomerInfo(reqDto1);
			resDto.setId(customerInfoDto.getId());
			resDto.setResult(ResultEnum.SUCCESS.getNo());
		} catch (Exception e) {
			logger.error("AddOrEditCustomerInfoHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("新增/编辑客户信息失败!");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
